#!/bin/sh -e
#
# zzz-upgrade
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

BOOTSTRAP_WORK_DIR=/etc/kpc

upgrade_file="$BOOTSTRAP_WORK_DIR/upgrade.sh"
upgrade_bak="${upgrade_file}_bak"
upgrade_done="${upgrade_file}_done"
upgrade_lock="${upgrade_file}_lock"

if [ -x $upgrade_file ]; then
  if [ -f $upgrade_done ]; then
    mv -f $upgrade_file $upgrade_bak
  else
    (flock -x $upgrade_lock -c "$upgrade_file")&
  fi
fi

exit 0
